<?php
$table = $this->uri->segment(3,0);
$url_ajax = base_url().'admin/ajax_field/order';
$url_ajax_sotrang = base_url().'admin/ajax_field/num';
$url_ajax_pub = base_url().'admin/ajax_field/pub/'.$table;
$url_ajax_where = base_url().'admin/ajax_field/where/'.$table;
?>
<!-- Noi dung bai viet-->
<script>
$(document).ready(function(){
    //*******************AJAX HIEN****************************************
    $('.ajax_hien').click(function(){
        var name = $(this).attr('name');
        var nclass = $(this).attr('class');
        var data =1;
        if(nclass=="ajax_hien"){
            data =0;
        }else{
            data=1;
        }
        var diachi = '<?php echo base_url().'admin/ajax/';?>'+name;
        //alert(diachi);       
        $.ajax({
          		type: "POST",
          		url: diachi,
          		data: {data: data},
                success: succes,
                error: err
        		});
    })
    //*******************order ajax****************************************
    $(".box_noidung .ajax").click(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).attr('href');
        var url1 = '<?php echo $url_ajax;?>';
        $.ajax({
          		type: "POST",
          		url: url1,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    //********************* loc du lieu***********************************
    $(".chon_option .locdulieu").change(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).val();
        var url2 = '<?php echo $url_ajax_where;?>';
        $.ajax({
          		type: "POST",
          		url: url2,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    //*********************chon so trang**********************************
    $(".chon_trang #sotrang").change(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).val();
        var url2 = '<?php echo $url_ajax_sotrang;?>';
        $.ajax({
          		type: "POST",
          		url: url2,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    function succes (data, status){
       // var id = '#p'+data;
        //alert(id);
        $(data).toggleClass('unpublish');
    }
    function callback(data, status){
        location.reload();
        //$("div .box_ajax").html(data);
      }
    
	function err(xhr, reason, ex){
	   alert('loi');
        $("div .box_ajax").html('loi');
      }
//*****************end order ajax******************/
});

</script>

<div class="baiviet_admin">
<form method="POST" action="<?php echo base_url().'admin/xuly/option/them';?>">
<div class="box_heading">
    <div class="icon">
    <img src="<?php echo base_url().'skin/admin/images/icon_sitemap.png';?>"/> 
    Sản phẩm: <?php 
    if($this->session->userdata('thongbao')){
        echo '<img src='.base_url().'skin/admin/images/ok.png class="ok"><font color=red><b>'.$this->session->userdata('thongbao').'</b></font>';
        $this->session->unset_userdata('thongbao');
        }?>
    </div>
    <div class="right">
    <a href="<?php echo base_url().'admin/xuly/option/edit/';?>"><img src="<?php echo base_url().'skin/admin/images/themmoi.png';?>"/>Thêm mới </a>
    </div>
</div>

<div class="box_noidung">
<table class="form">
<tr>
    <th style="width:5%"><a class="ajax" href="id">id</a><?php if($this->session->userdata('order')=='id'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th ><a title="Tiêu đề" class="ajax" href="title">Tiêu đề</a><?php if($this->session->userdata('order')=='title'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th style="width:5%"><a title="Ẩn hiện" class="ajax" href="publish">Status</a><?php if($this->session->userdata('order')=='publish'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th style="width:5%">Sửa</th>
    <th style="width:5%">Xóa</th>
    
</tr>
<?php 

if(!empty($data)){
    foreach ($data as $data){
        echo '
        <tr>
        <td>'.$data->id.'</td>
        <td>'.$data->title.'</td>';
       if($data->publish){
        echo '<td> <div class="ajax_hien" id="p'.$data->id.'" name="'.$table.'/publish/'.$data->id.'/p'.$data->id.'" ></div></td>';
        }else echo '<td><div  id="p'.$data->id.'" class="ajax_hien unpublish" id="unpublish" name="'.$table.'/publish/'.$data->id.'/p'.$data->id.'"></div></td>';								
                                            
        echo '
        <td><a href="'.base_url().'admin/xuly/option/edit/'.$data->id.'" class="edit"><img src="'.base_url().'skin/admin/images/edit.png" title="Sửa"></a></td>
        <td><a onclick="return confirm(\'Bạn có muốn xóa không?\');" href="'.base_url().'admin/xuly/option/xoa/'.$data->id.'"><img src="'.base_url().'skin/admin/images/xoa.png" title="xóa"></a></td>
        
        </tr>                           
        ';
    }                          
                                
}?>

</table>
<!--chon so traang-->
<div class="chon_trang">
Số bài hiển thị:
<select name="sotrang" id="sotrang" class="inputbox" size="1">
<?php 
for( $i=10;$i<=100;$i){ 
    echo '<option value="'.$i.'" ';
    if($this->session->userdata('rows_per_page_baiviet')==$i){echo 'selected="selected"';}
    echo '>'.$i.'</option>';
    $i=$i+10;
}
for( $i=200;$i<=500;$i){ 
    echo '<option value="'.$i.'" ';
    if($this->session->userdata('rows_per_page_baiviet')==$i){echo 'selected="selected"';}
    echo '>'.$i.'</option>';
    $i=$i+100;
}
 
 ?>
</select>
</div>
<!--end chon so trang-->

<!--phan trang-->
	<div class="pagination pagination-left">
		<div class="results">
			<span><?php if($result_mensenger){echo $result_mensenger;}?></span>
		</div>                            
		<ul class="pager">
		<?php	echo $this->pagination->create_links();?>
		</ul>   
	</div>
<!-- end phan trang-->
</div>
</form>
</div>
<!--end noi dung bai viet-->